<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fns" uri="http://java.sun.com/jsp/jstl/functionss" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <title>车辆列表</title>
    <jsp:include page="../../body/link-page.jsp" flush="true"/>
</head>

<body>
<div class="panel" >
    <form id="form" action="/car/cars/list" method="post">
    <div class="panel-heading hide">
        <button type="button" id="demo-dt-addrow-btn" class="btn btn-info" onclick="LAYER.addLayerWithSize('layer_parkingAdd','添加停车场','/car/parking/add','800px','620px')">
            <i class="fa fa-plus"></i> 添加
        </button>
        <button type="button" class="btn btn-success" onclick="toEdit();"><i class="fa fa-edit"></i>修改</button>
        <button type="button" class="btn btn-primary" onclick="deleteAll();"><i class="fa fa-trash-o"></i>删除</button>
    </div>


        <div class="panel-body" id="table-box">
            <table id="table" class="table table-striped table-bordered dataTable no-footer dtr-inline"
                   cellspacing="0" width="100%" role="grid" aria-describedby="demo-dt-addrow_info"
                   style="width: 100%;"
                   data-pn="${carsList.pageNum}" data-ps="${carsList.pageSize}" data-tp="${carsList.totalPage}"
                   data-tr="${carsList.totalRecord}">
                <thead>
                <tr role="row">
                    <th style="width: 20px;"><input type="checkbox" id="check-all"/></th>
                    <th>姓名</th>
                    <th>车牌号</th>
                    <th>标识</th>
                    <th>创建时间</th>
                    <th>备注</th>
                </tr>
                </thead>
                <tbody>
                <c:forEach var="cars" items="${carsList.results}" varStatus="status">
                    <tr role="row" class="odd">
                        <td><input type="checkbox" value="${cars.id}"/></td>
                        <td>${cars.name}</td>
                        <td>${cars.numberPlates}</td>
                        <td>
                            <c:if test="${cars.status == 2}">普通车辆</c:if>
                            <c:if test="${cars.status == 1}">默认车辆</c:if>
                        </td>
                        <td>${fns:dateToStringTime(cars.createTime)}</td>
                        <td>${cars.info}</td>
                    </tr>
                </c:forEach>
                </tbody>
            </table>
            <ul class="pagination"></ul>
        </div>

    </form>
</div>
</body>
<jsp:include page="../../body/javascript-page.jsp" flush="true"/>
<script type="application/javascript">
    function toEdit(){
        var id = getAllCheck("form");
        if(id.length != 1){
            layer.msg("请选择一条数据",{icon:0,timeout:1000});
        } else {
            LAYER.addLayerWithSize("layer_parkingEdit","修改停车场","/car/parking/edit?id="+id,"800px","620px");
        }
    }
    function  deleteAll() {
        var  ids=getAllCheck("form");
        if(ids.length <=0){
            layer.msg("请选择删除的数据",{icon:0,timeout:1000});
        }else{
            layer.confirm("确定要删除" + ids.length + "条数据？",{title:"提示",btn:["确定","取消"]},function () {
                $.ajax({
                    type:"POST",
                    url:"/car/parking/deleteDataByIds",
                    dataType:"json",
                    data:{"ids":ids.join(",")},
                    success:function (data) {
                        if(data.success){
                            layer.msg("删除成功",{icon:1,timeout:1000});
                            reloadPage();
                        } else {
                            layer.msg("删除失败",{icon:2,timeout:1000});
                        }
                    }
                    });
            });

        }

     }

    function parentSet(picture) {
        var id=picture.id;
        $(".img-id").val(picture.id);
        var imgDiv= $(".layui-upload-drag");
        imgDiv.empty();
        var img=document.createElement("img");
        img.className="img-parking";
        img.src=picture.src;
        img.setAttribute("max-width","100%");
        img.setAttribute("height","100%");
        img.onerror="${basePath}/static/img/head/default-head.jpg";
        imgDiv[0].appendChild(img);
        imgDiv.css("border-color" ,"#FFFAFA");
        imgDiv.css("background-color" ,"#FFFAFA");
    }
</script>
</html>
